package org.jeecg.modules.system.service.impl;

import org.jeecg.common.util.RedisUtil;
import org.jeecg.glr.util.GLRConstant;
import org.jeecg.modules.system.entity.SysInternationalLang;
import org.jeecg.modules.system.mapper.SysInternationalLangMapper;
import org.jeecg.modules.system.service.ISysInternationalLangService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 国际化
 * @Author: jeecg-boot
 * @Date:   2020-07-13
 * @Version: V1.0
 */
@Service
public class SysInternationalLangServiceImpl extends ServiceImpl<SysInternationalLangMapper, SysInternationalLang> implements ISysInternationalLangService {


    @Resource SysInternationalLangMapper sysInternationalLangMapper;

    @Resource
    RedisUtil redisUtil;

    @Override
    public void getAllLang() {
       List<SysInternationalLang> list=sysInternationalLangMapper.getAllLang();
        redisUtil.del(GLRConstant.SYS_INTERNATIONAL_LANG_CN);
        redisUtil.del(GLRConstant.SYS_INTERNATIONAL_LANG_EN);
        for (SysInternationalLang lg :
                list) {
            if(GLRConstant.SYS_INTERNATIONAL_LANG_CN.equals(lg.getLangCode())){
                redisUtil.putMap(GLRConstant.SYS_INTERNATIONAL_LANG_CN,lg.getLangKey(),lg.getLangContext());
            } else  if(GLRConstant.SYS_INTERNATIONAL_LANG_EN.equals(lg.getLangCode())){
                redisUtil.putMap(GLRConstant.SYS_INTERNATIONAL_LANG_EN,lg.getLangKey(),lg.getLangContext());
            }
        }
    }
}
